/*
 * @Author: your name
 * @Date: 2021-05-23 19:38:09
 * @LastEditTime: 2021-06-06 12:36:26
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /xiangpan-admin/src/pages/store/storeModal/index.tsx
 */
/*
 * @Author: your name
 * @Date: 2021-05-23 19:37:51
 * @LastEditTime: 2021-05-23 19:37:51
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /xiangpan-admin/src/pages/store/storeModal.tsx
 */
/*
 * @Author: your name
 * @Date: 2021-05-19 17:22:23
 * @LastEditTime: 2021-05-23 19:02:35
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /xiangpan-admin/src/pages/home/scheduModal/index.tsx
 */
import { IFormTypeEnum } from '@/components/form/formComponent';
import { Modal } from 'antd';
import HeaderForm from '@/components/form';

import React, { useEffect } from 'react';
import { SEX } from '@/enum';
import { FormInstance } from 'antd';
import { add_store, edit_store, get_chains } from '@/services/pages';
import useObj from '@/use/useObj';
import { globalModel } from '../../globalModel';
import { observer } from 'mobx-react';
import { IForm } from '../../../components/form/interface';
import { toJS } from 'mobx';
interface IProps {
  visible: boolean;
  close: () => void;
  refresh: () => void;
  row?: any;
}

const StoreModal = (props: IProps) => {
  console.log(globalModel.chainList, 'globalModel==');

  const List: IForm[] = [
    // {
    //   key: 'chain_id',
    //   type: IFormTypeEnum.Select,
    //   label: '连锁店',
    //   rules: [{ required: true }],
    //   data: {
    //     list: globalModel.chainList,
    //     fieldNames: { value: 'chain_id', label: 'chain_name' },
    //   },
    // },
    {
      key: 'store_name',
      type: IFormTypeEnum.Input,
      label: '门店名称',
      rules: [{ required: true }],
    },
    {
      key: 'clock_price',
      type: IFormTypeEnum.InputNumber,
      label: '点钟价格',
      rules: [{ required: true }],
    },
    {
      key: 'device_no',
      type: IFormTypeEnum.Input,
      label: '小票机设备号',
    },
    {
      key: 'device_key',
      type: IFormTypeEnum.Input,
      label: '设备key',
    },
  ];

  useEffect(() => {
    // globalModel.getChains();
  }, []);

  const onFinish = async (values: any, form: FormInstance) => {
    values.clock_price = values.clock_price * 100;
    console.log(form, 'form===');
    if (props.row?.store_id) {
      await edit_store({ ...values, store_id: props.row.store_id });
    } else {
      await add_store(values);
    }
    props.close();
    props.refresh();
  };

  return (
    <Modal
      maskClosable={false}
      visible={props.visible}
      title={props.row?.store_id ? '编辑门店' : '添加门店'}
      footer={null}
      onCancel={props.close}
    >
      <HeaderForm
        labelwidth={110}
        layout="horizontal"
        list={List}
        onSubmit={onFinish}
        initialValues={{
          ...props.row,
          clock_price: props.row?.clock_price / 100,
        }}
      />
    </Modal>
  );
};
export default observer(StoreModal);
